<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" th:src="@{/static/js/jquery-3.4.1.js}"></script>
</head>
<body>
<div id="login">
    登录名:<input type="text" id="userName"/>
    密码:<input type="text" id="password"/>
    <button id="loginBtn" onclick="login()">登陆</button>
</div>
<div id="loginSuccess">

</div>
</body>
<script type="text/javascript">
    function login() {
        $.ajax({
            //请求方式
            type: "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url: "http://localhost:8081/login/login?userName=" + $("#userName").val() + "&password=" + $("#password").val(),
            //请求成功
            success: function (result) {
                var data = result;//JSON.parse(result);
                if (data.success || data.success === 'true') {
                    $("#login").hide();
                    $("#loginSuccess").text(data.msg);
                } else {
                    alert(data.msg);
                }
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }
</script>
</html>